#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import time
import os

def get_process_num():
    return len([d for d in os.listdir("/proc") if d.isdigit()])

def create_record(value):
    record = {}
    record['Metric']      = "process.num"
    record['Endpoint']    = os.uname()[1]
    record['Timestamp']   = int(time.time())
    record['Step']        = 60
    record['Value']       = value
    record['CounterType'] = 'GAUGE'
    record['TAGS']        = ''
    return record

if __name__ == '__main__':
    data=[]
    value = get_process_num()
    data.append(create_record(value))
    print json.dumps(data)
